"‘The trend is your friend’, as they say on the trading floor."
"What really is a trend? ... To a trader, a trend is a series of higher highs or lower lows."
James, Jessica. "Simple trend-following strategies in currency trading." Quantitative Finance, 3(4), 364-374, 2003. here

where
\Desktop\M8674\Notebooks\Follow_the_Trend.jlChoose to save the notebookShift + Enter or use the "Run" buttonbegin
using PlutoUI, Dates, SparseArrays , StatsBase, PlutoPlotly, PlotlyKaleido
using CSV , DataFrames, LinearAlgebra , TimeSeries, NLsolve, LaTeXStrings
force_pluto_mathjax_local(true)
PlotlyKaleido.start(;mathjax = true)
end
TableOfContents()
Shift + Enter or use the "Run" buttonhtml"""
<style>
@media screen {
main {
margin: 0 auto;
max-width: 1600px;
padding-left: max(200px, 10%);
padding-right: max(383px, 10%);
# 383px to accommodate TableOfContents(aside=true)
}
}
</style>
"""
open a new cell and turn it into a Markdown cell
Ctrl + M then Enteruse the # symbol to create title sections, and subsections:
# for the main title## for a subtitle### for a sub-subtitleRun the cell: Shift + Enter or use the "Run" button
Add your name, date, etc. using the same procedure in the notebook
The easiest way to simulate this equation is to use a for loop.
Consider the following baseline version:
The code is given next.
begin
n = 49 # Number of iterations
μ = 1.0 # Parameter: μ value
α = 1.0 # Parameter: α value
ξ = 0.75 # Parameter: ξ value
π_1 = [ 2.0 2.0 ] # Setting the initial conditions (π₁=2.0, π₂=2.0)
#l = length(π_1) # Not very useful in simple models
ϵ = zeros(1 , n+1) # Defining the shocks, ϵ = zeros(l-1 , n+1) is an alternative
ϵ[20] = 0.5 # Inserting the only shock at t=20
π = [π_1 zeros(1, n-1)] # Pre-allocating space; alternative is π = [π_1 zeros(l-1, n-1)]
for t = 1 : n-1
π[t+2] = μ * (α * π[t+1] + ξ * (π[t+1] - π[t]) + ϵ[t+2]) # the equation to be iterated
end
end
plot(π', mode = "markers+lines", line_width = 0.4)
Cagan, Philip (1956). The Monetary Dynamics of Hyperinflation. In Studies in the Quantity Theory of Money, ed. Milton Friedman, 25-117, University of Chicago Press.
Friedman, Milton (1957). A Theory of the Consumption Function. Princeton University Press.
Start with the eq. (5) above:
Isolate
Iterate eq. (6) backward
To secure a stable solution in eq. (7a) we have to impose:
If we assume
And the stable solution will be:
Main message: expected price level depends on past price levels through an exponential smoothing process.
Consider a lag of 5 periods (quarters) and fast correction
Looks great?
No, it looks quite poor.
The error in the forecasting exercise is large and systematic.
Let's see what happens in the case of a stationary variable (inflation rate).
The vindication of Adaptive Expectations!
The mean of the mistakes is zero:
Its dynamics will be expressed at the
If
If
If
Another excellent treatment of adaptive expectations can be found in the textbook:
Ben J. Heijdra (2017). Foundations of Modern Macroeconomics. Third Edition, Oxford UP, Oxford.
A step-by-step derivation of equation (7) in the next slides
We will solve the following equation by backward iteration:
Like this, when
The strategy is as follows:
In the previous slide, we iterated backwards 3 times.
The result was:
A step-by-step derivation of equation (9) in the following slides
We will solve the following equation by backward iteration:
Like this, when
The strategy is as follows:
In the previous slide, we iterated backwards 3 times.
The result was: